import defaultSettings from '@/settings'

const { showSettings, tagsView, fixedHeader, sidebarLogo, theme } = defaultSettings

const state = {
    theme: theme || '#409EFF', // 主题色
    showSettings: showSettings || true, // 是否显示设置面板
    tagsView: tagsView || true, // 是否显示标签导航
    fixedHeader: fixedHeader || true, // 是否固定头部
    sidebarLogo: sidebarLogo || true // 是否显示侧边栏Logo
}

const mutations = {
    CHANGE_SETTING: (state, { key, value }) => {
        // 确保key存在于state中
        if (Object.prototype.hasOwnProperty.call(state, key)) {
            state[key] = value
        }
    }
}

const actions = {
    // 修改设置
    changeSetting({ commit }, data) {
        commit('CHANGE_SETTING', data)
    },

    // 修改主题色
    changeTheme({ commit }, theme) {
        commit('CHANGE_SETTING', { key: 'theme', value: theme })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
} 